<?php
/**
 * Created by PhpStorm.
 * User: hui
 * Date: 2016/9/10
 * Time: 10:48
 */
namespace Common\Model;

use Common\Model\CommonModel;

class OrderResmsmModel extends CommonModel
{

    /**
     * 根据order_resmsm查询9个跑客的信息
     * @return $message
     */
    function  pk_order_detail()
    {
        $dispatch = D('Dispatch');
        $order_data = $this->order('order_time')->limit(9)->field('dispatch_id,order_data')->where('pay_status=1 AND status="2"')->select();
        $ak = 'OkM4ci06ibVrimvizgsIWv0sjASIa7BK';
        $data = array();
        foreach ($order_data as $k => $v) {
            $dispatch_id = $v["dispatch_id"];
            $data[$k]["order_data"] = json_decode($v["order_data"], true);
            // dump($data[$k]["order_data"]);
            //获取跑客起始地
            $message[$k]["send_address"] = $data[$k]["order_data"]["send_address"] . $data[$k]["order_data"]["send_address_floor"];
            $lat = $data[$k]["order_data"]["send_latit"];
            $lng = $data[$k]["order_data"]["send_longit"];
            //获取跑客名字
            $message[$k]["dispatch_name"] = $dispatch->where("dispatch_id = $dispatch_id")->getField('dispatch_name');

            //根据名字截取姓氏 :王小波 变为 王师傅已接单 送往
//            $message[$k]["dispatch_name"] = $message[$k]["order_name2"][0]["dispatch_name"];
            $message[$k]["dispatch_name"] = substr($message[$k]["dispatch_name"], 0, 3) . "师傅已接单  ";

            //获取跑客周围的一个business点
            $location = "$lat" . ",$lng";
            $url = "http://api.map.baidu.com/geocoder/v2/?ak=$ak&location=$location&output=json&pois=1";
            $json = file_get_contents($url);
            $data = json_decode($json, true);
//            dump($data);
            $message[$k]["data"] = $data;
            $message[$k]["business"] = $message[$k]["data"]["result"]["addressComponent"]["district"];
            unset($message[$k]["data"]);
        }
        return $message;
    }


}